package ca.cbc.medialib.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

@XmlTransient
@Entity
@Table(name = "failed_media")
public class FailedMedia {
    private long releaseId;
    private long mediaId;
    private long yospaceId;
    private String title;
    private String releaseUrl;
    private Date failedDate;


    public FailedMedia() {
    }

    public FailedMedia(long releaseId, long mediaId, long yospaceId, String title, String releaseUrl, Date failedDate) {
        this.setReleaseId(releaseId);
        this.setMediaId(mediaId);
        this.setYospaceId(yospaceId);
        this.setTitle(title);
        this.setReleaseUrl(releaseUrl);
        this.setFailedDate(failedDate);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FailedMedia fm = (FailedMedia) o;
        if (this.getReleaseId() != fm.getReleaseId() || this.getMediaId() != fm.getMediaId()
                || this.getYospaceId() != fm.getYospaceId())
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = title != null ? title.hashCode() : (int) (releaseId % 1000l);
        result = 31 * result;
        return result;
    }

    @Column(name = "air_date")
    public Date getFailedDate() {
        return failedDate;
    }

    @Column(name = "media_id")
    public long getMediaId() {
        return mediaId;
    }

    @Id
    @Column(name = "release_id")
    public long getReleaseId() {
        return releaseId;
    }

    @Column(name = "release_url")
    public String getReleaseUrl() {
        return releaseUrl;
    }

    public String getTitle() {
        return title;
    }

    @Column(name = "yospace_id")
    public long getYospaceId() {
        return yospaceId;
    }

    public void setFailedDate(Date failedDate) {
        this.failedDate = failedDate;
    }

    public void setMediaId(long mediaId) {
        this.mediaId = mediaId;
    }

    public void setReleaseId(long releaseId) {
        this.releaseId = releaseId;
    }

    public void setReleaseUrl(String releaseUrl) {
        this.releaseUrl = releaseUrl;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setYospaceId(long yospaceId) {
        this.yospaceId = yospaceId;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("FailedMedia");
        sb.append("{releaseId=").append(releaseId);
        sb.append(", mediaId=").append(mediaId);
        sb.append(", yospaceId=").append(yospaceId);
        sb.append(", title='").append(title).append('\'');
        sb.append(", releaseUrl='").append(releaseUrl).append('\'');
        sb.append(", failedDate=").append(failedDate);
        sb.append('}');
        return sb.toString();
    }
}
